/*

Frequency of use: 1 2 3 [4] 5 MEDIUM HIGH

Short:
    Strategy is an algorithm that you pass into a function or class that uses 
the strategy.  The idea is that you can provide a different strategy to achieve 
something different.

Long:
    The strategy pattern (also known as the policy pattern) is a particular 
software design pattern, whereby algorithms can be selected at runtime.
In some programming languages, such as those without polymorphism, the issues 
addressed by this pattern are handled through forms of reflection, such as the 
native function pointer or function delegate syntax.
This pattern is invisible in languages with first-class functions. See the 
Python, Scala or Perl implementations for examples.
The strategy pattern is useful for situations where it is necessary to 
dynamically swap the algorithms used in an application. The strategy pattern is 
intended to provide a means to define a family of algorithms, encapsulate each 
one as an object, and make them interchangeable. The strategy pattern lets the 
algorithms vary independently from clients that use them.

Information sources:
 - http://calumgrant.net/patterns/index.html
 - http://en.wikipedia.org/wiki/Strategy_pattern
 - http://www.dofactory.com/Patterns/Patterns.aspx
*/

#include <iostream>
#include <string>

class Strategy
{
public:
	virtual ~Strategy() { }
	virtual std::string format(const std::string &, const std::string &) const=0;
};

class Formatter : public Strategy
{
public:
	std::string format(const std::string & s1, const std::string & s2) const
	{
		return s1 + " " + s2 + "!";
	}
};

void hello_world(const Strategy & strategy)
{
	std::cout << strategy.format("Hello", "world") << std::endl;
}

int main()
{
	hello_world(Formatter());
	return 0;
}

